﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Nonocast.Scheduling.ConsoleApplication {
	public class Program {
		static void Main(string[] args) {
			var p = new List<PlayElement> {
				new PlayElement("picture1"),
				new PlayElement("picture2"),
				new PlayElement("picture3"),
				new PlayElement("picture4"),
				new PlayElement("picture5")
			};

			var schedule = new ScheduleImpl<PlayElement> {
				new DaysOfWeek<PlayElement>(p[0]).AllDay().EveryDay(),
				new DaysOfWeek<PlayElement>(p[1]).From("9:00").Until("18:00").EveryWorkday(),
				new DaysOfWeek<PlayElement>(p[1]).From("11:00").Until("15:00").Weekends(),
				new DaysOfWeek<PlayElement>(p[2]).From("9:30").Until("10:45").Mon().Wed().Fri(),
				new DaysOfWeek<PlayElement>(p[2]).From("14:00").Until("16:30").Tue().Sat(),
				new Once<PlayElement>(p[3]).Today().From("20:00").UntilDayEnd(),
				new Once<PlayElement>(p[3]).In("2013/2/5").From("17:00").Until("21:00"),
				new Once<PlayElement>(p[4]).In("2013/2/7").From("16:00").Until("17:00"),
				new Once<PlayElement>(p[4]).In("2013/2/6").From("0:58").Until("1:00"),
				new DaysOfWeek<PlayElement>(p[4]).From("0:55").Until("1:00").EveryDay(),
				new DaysOfWeek<PlayElement>(p[2]).From("14:26:30").Until("18:00").EveryDay(),
				new DaysOfWeek<PlayElement>(p[3]).From("14:26:45").Until("18:00").EveryDay(),
				new Once<PlayElement>(p[0]).From(DateTime.Now.AddSeconds(10)).Until(DateTime.Now.AddSeconds(30)).Today(),
				new DaysOfWeek<PlayElement>(p[1]).From(DateTime.Now.AddSeconds(10)).Until(DateTime.Now.AddSeconds(30)).EveryDay(),
				new DaysOfWeek<PlayElement>(p[2]).From(DateTime.Now.AddSeconds(10)).Until(DateTime.Now.AddSeconds(30)).EveryDay()
			};

			var scheduler = new SchedulerImpl<PlayElement>(schedule);
			scheduler.TaskEvent += (s1, e1) => {
				var arg = e1 as TaskEventArgs<PlayElement>;
				Console.WriteLine("{0} (#{1})", arg.Task.Context, arg.Task.GeneratedBy.Priority);
			};
			scheduler.Run();

			Console.WriteLine("press any key to exit.");
			Console.ReadLine();
			scheduler.Close();
			Console.ReadLine();
		}
	}

	public class PlayElement {
		public string Name { get; set; }
		public PlayElement() { }
		public PlayElement(string name) { this.Name = name; }
		public override string ToString() {
			return Name;
		}
	}
}
